window.addEventListener("load",initilaPhotosF);

function initilaPhotosF(e){
	var photoPre=document.getElementById("photoPre");
	var photoNext=document.getElementById("photoNext");
	var photoCountInfo=document.getElementById("photoCountInfo");
	var currentPhotoInfo=document.getElementById("currentPhotoInfo");
	
	var pics=document.getElementsByClassName("photoItem");
	
	var currentPicIndex=0;
	
	pics[currentPicIndex].setAttribute("current","");
	photoCountInfo.innerHTML=(currentPicIndex+1)+" / "+pics.length;
	currentPhotoInfo.innerHTML=pics[currentPicIndex].getAttribute("picInfo");
	
	photoPre.addEventListener("click",setPrevPicF);
	photoNext.addEventListener("click",setNextPicF);
	
	function setCurrentPic(toIndex){
		pics[currentPicIndex].removeAttribute("current");
		pics[toIndex].setAttribute("current","");
		photoCountInfo.innerHTML=(toIndex+1)+" / "+pics.length;
		currentPhotoInfo.innerHTML=pics[toIndex].getAttribute("picInfo");
		currentPicIndex=toIndex;
	}
	
	function setPrevPicF(e){
		if(currentPicIndex==0){
			setCurrentPic(pics.length-1);
		}else{
			setCurrentPic(currentPicIndex-1);
		}
	}
	
	function setNextPicF(e){
		if(currentPicIndex==pics.length-1){
			setCurrentPic(0);
		}else{
			setCurrentPic(currentPicIndex+1);
		}
	}
	
}